<template>
  <div class="loginForm">
    <h1 style="text-align: center;margin-top: -20px;">登录</h1>
    <el-form :model="loginForm" :rules="rules" ref="loginForm">
      <el-form-item prop="username">
        <el-input type="text" v-model="loginForm.username" placeholder="请输入账号名" clearable></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="loginForm.password" autocomplete="false" placeholder="请输入密码"
                  clearable></el-input>
      </el-form-item>
      <el-form-item :span="11" prop="code">
        <el-input style="margin-right: 5px; display: flex;flex-direction: row;" type="text" v-model="loginForm.code"
                  autocomplete="true" placeholder="请输入验证码" clearable></el-input>
        <img style="width: 100px; height: 40px;margin-right: 0px;" :src="imageURl">
      </el-form-item>
      <el-form-item style="text-align: left;margin: 0px 0px;">
        <el-checkbox v-model="checked">记住我</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button style="width: 100%;font-size: 25px;" type="primary" @click="submitForm">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'login',
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
        code: ''
      },
      imageURl: '',
      checked: true,

      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
        ],
        code: [{
          required: true, message: '输入验证码', trigger: 'blur'
        }]
      }

    }
  },

  methods: {
    submitForm() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          alert('submit!');
          this.$router.push('/hello');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },


  }
}
</script>
<style>
.loginForm {
  width: 400px;
  height: 300px;
  margin: 100px auto;
  padding: 50px;
  border-radius: 15px;
  box-shadow: #a8a6a4 0px 0px 30px 10px;
}

.el-form-item__content {
  display: flex;
  align-items: center;
}
</style>